#ifndef __cplusplus
#error "C++!"
#endif
#include <iostream>
#include <cstdio>
#include <sqlite3.h>
#define MAX_TRIES 10
namespace fullMetal{
	class sqlErr{
		private:
			unsigned int x;
			std::string v;
		public:
			sqlErr(std::string b,int a):x(a),v(b){}
			operator int(){return x;}
			operator std::string& (){return v;}
			void out(){
				std::cout<<v<<x<<std::endl;
			}
	};
	int outlineRow(void* nUsed,int argc,char** argv,char** col){
		for(int i=0;i<argc;i++) printf("%s = % -15s\t",col[i],(argv[i]!=NULL)?argv[i]:"NULL");
		printf("\n");
		return 0;
	}
	class SQL{
		private:
			sqlite3* DB;
			sqlite3_stmt *stmt;
		public:
			SQL(std::string fn = "database.db"){
				int error = sqlite3_open(fn.c_str(),&DB);
				if( error ){
					sqlErr sError(("Couldn't open file: " + fn ),error);
					sError.out();//throw(sError);
				}
			}
			SQL& operator = (std::string exec){
				Query(exec);
				return *this;
			}
			void Query(std::string query,int (*callback)(void*,int,char**,char**) = NULL,void* val = NULL){
				char* err = NULL,*q = (char*)query.c_str();
				sqlite3_exec(DB,q,callback,NULL,&err);
				if(err){
					std::string str ="queryERR: ";
					str+=err;
					str+="\"";
					sqlErr sError( str,0);
					sqlite3_free(err);
					sError.out();//throw (sError);
				}
			}
			char* getString(int column){
				return(char*)sqlite3_column_text(stmt,column);
			}
			~SQL(){
				sqlite3_close(DB);
			}
	};
}

